<?
/**
 * This file is part of XNAT light.
 *
 * XNAT light is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * XNAT light is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with XNAT light.  If not, see <http://www.gnu.org/licenses/>.
 */
use NRG\Framework\Controllers\Error as ErrorController;
use NRG\Framework\Exceptions\ClassException as ClassException;
use NRG\Framework\Common\Registry as Registry;
use NRG\Framework\Common\Session as Session;
use NRG\Common\LoginManager as LoginManager;

// register exception handler
set_exception_handler("exception_handler");

/**
 * Autoloader
 *
 * @param string $name
 */
function __autoload($name=null)
{
    $class = explode("\\", $name);
    $class = implode("/", $class);

    $path = dirname(__FILE__) . "/../..";
    $fullfile = "$path/$class.php";

    if(!file_exists($fullfile))
    	throw new ClassException(ClassException::CLASS_NOT_FOUND, $name);
    
    include_once($fullfile);
}

/**
 * Default exception handler.
 *
 * For now we're explicitely forwarding to Controller/Error
 *
 * Eventually we will extend the Framework initialization as a class
 * that may accept or proxy routing. Then we can do fancier stuff like
 * re-routing to different controllers.
 */
function exception_handler($e)
{
    new ErrorController($e);
}
